<?php

header('Content-Type:application/json; charset=utf-8'); #返回json
session_start();

if(empty($_SESSION['userinfo'])){
    //未登录，引导登录
    $result = [
        'code' => '-1',
        'msg' => '未登录，请登录',
    ];
    echo json_encode($result);
    exit ;

}

$work_id=  $_GET["work_id"]??-1;
// $sub_id=  $_GET["sub_id"] ?? -1;

        
try {
    $dbh = new PDO("mysql:host=127.0.0.1;dbname=g09short", 'root', 'G09short.'); //初始化一个PDO对象
    $sql ="SELECT work_id,work_title,work_endtime,work_content,work_img1,work_img2,work_img3,A.cou_id  FROM zyh_work A INNER JOIN zyh_course B ON A.cou_id=B.cou_id WHERE A.work_id= ".$work_id;
    $stmt = $dbh->query($sql,    PDO::FETCH_ASSOC);
    $dbh=null;
    if ($stmt -> rowCount() == 0){
        $res= [
            'code' => '1',
            'msg' => '无数据',
        ];
    }
    else{
        
        $data = $stmt->fetchAll();
        $res= [
            'code' => '0',
            'msg' => '获取数据成功',
            'data' => $data,
        ];
    }

} catch (PDOException $e) {
    
    $res=  [
        'code' => '5',
        'msg' => '出错',
    ];
}


//返回json
echo json_encode($res);
